package action.chap11;

import java.util.Random;
import java.util.concurrent.*;

public class Demo01 {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        System.out.println("sunfeng".charAt(0) * new Random().nextDouble());
        Future<Double> submit = executorService.submit(() -> {
            TimeUnit.SECONDS.sleep(2);
            return 1.0;
        });
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        try {
            Double aDouble = submit.get(1, TimeUnit.SECONDS);
            System.out.println(aDouble);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            e.printStackTrace();
        }
        executorService.shutdown();
    }
}
